package com.charging.business.utils;


/**
 * @author JerryLu
 * @date 2024/10/9 16:09
 * @description 相关金额计算
 */
public class PayUtil {

    /**
     * 计算MTC最终收费金额，四舍五入
     *
     * @param amount
     * @return
     */
    public static int mtcFinalFee(int amount) {
        int muti = amount / 100;
        int mode = amount % 100;

        if (mode >= 50) {
            muti++;
        }

        return muti * 100;
    }

    /**
     * 四舍五不入
     * 十位小于等于4，舍去十位及个位，否则保留
     *
     * @param d
     * @return
     */
    public static int round40(int d) {
        int temp = d % 100;
        if (temp < 50) {
            //十位小于等于4
            return d - temp;
        } else {
            return d;
        }
    }

    /**
     * 百位四舍五入
     *
     * @param d
     * @return
     */
    public static int round100(int d) {
        return (d / 100 + (d % 100 >= 50 ? 1 : 0)) * 100;
    }

    public static double convertFee(int fee) {
        return (double) fee / 100;
    }

    public static double convertMileage(int mileage) {
        return (double) mileage / 1000;
    }

    /**
     * 计算ETC最终收费金额
     * 四舍五不入95折
     *
     * @param amount
     * @return
     */
    public static int etcFinalFee(int amount) {
        int mu = amount / 100;
        int md = amount % 100;

        if (md < 50) {
            amount = mu * 100;
        }

        int rate = 95;
        int prod = amount * rate;
        int muti = prod / 100;
        int mode = prod % 100;

        if (mode >= 50) {
            muti++;
        }

        return muti;
    }

    /**
     * 计算ETC-95折优惠金额
     *
     * @param amount
     * @return
     */
    public static int etc095Fee(int amount) {
        int rate = 95;
        int prod = amount * rate;
        int muti = prod / 100;
        int mode = prod % 100;

        if (mode >= 50) {
            muti += 1;
        }

        return muti;
    }
}
